package com.util;

import java.io.IOException;
import java.io.PrintWriter;
import java.io.Serializable;

import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;

import com.alibaba.fastjson.serializer.PropertyFilter;

public class AjaxUtil implements Serializable {
	
	public static void printString(int code) {
		HttpServletResponse response = ServletActionContext.getResponse();
		response.setCharacterEncoding("utf-8");
		try {
			PrintWriter out = response.getWriter();
			out.print(code);
			out.flush();
			out.close();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	public static void printString(String code) {
		HttpServletResponse response = ServletActionContext.getResponse();
		response.setCharacterEncoding("utf-8");
		try {
			PrintWriter out = response.getWriter();
			out.print(code);
			out.flush();
			out.close();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public static PropertyFilter filterProperty(final String...strings) {
		PropertyFilter filter = new PropertyFilter() {
			
			@Override
			public boolean apply(Object arg0, String propertyName, Object arg2) {
				for (String string : strings) {
					if(propertyName.equals(string)) {
						return false;
					}
				}
				return true;
			}
		};
		return filter;
	}
	
}
